package com.unicdata.ai.demo_2af.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.unicdata.ai.demo_2af.common.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper <User> {

    /**
     * 根据用户ID获取权限列表
     *
     * @param userId 用户ID
     * @return 权限编码列表
     */
    @Select("SELECT p.permission_code FROM sys_user_role ur " +
            "LEFT JOIN sys_role_permission rp ON ur.role_id = rp.role_id " +
            "LEFT JOIN sys_permission p ON rp.permission_id = p.id " +
            "WHERE ur.user_id = #{userId}")
    List <String> selectPermissionsByUserId(@Param("userId") Long userId);

    /**
     * 根据用户ID获取角色列表
     *
     * @param userId 用户ID
     * @return 角色编码列表
     */
    @Select("SELECT r.role_code FROM sys_user_role ur " +
            "LEFT JOIN sys_role r ON ur.role_id = r.id " +
            "WHERE ur.user_id = #{userId}")
    List<String> selectRolesByUserId(@Param("userId") Long userId);
}
